package com.ss.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ss.security.MyInvocationSecurityMetadataSource;


public class WebLsn implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		System.out.println("Destroye...");
		servletContextEvent.getServletContext().removeAttribute("urlAuthorities");  
	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		System.out.println("Init...");
		getSecurityManager(servletContextEvent.getServletContext());
//		ServletContext servletContext = servletContextEvent.getServletContext();  
//		UserProvider userProvider = this.getSecurityManager(servletContext);  
//          
//        Map<String, String> urlAuthorities = userProvider.loadUrlAuthorities();  
//        servletContext.setAttribute("urlAuthorities", urlAuthorities);  
	}
	
	protected Object getSecurityManager(ServletContext servletContext) {  
	       Object obj =  WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean("securityMetadataSource");   
	       //((MyInvocationSecurityMetadataSource)obj).loadResourceDefine();
	          
	       return obj;
	   }

}
